require("../util.js");
require("../component/components.js");
require("../../jsMt/util.js");
var vm = new Vue({
    el:"#incomeAssets",
    data:{
        loginUid:"1",
        day:7,
        pageNumber:1,
        income:{},
        data:[],
        list:[],
        walletLog:{},
        walletLog1:[],
        walletLog2:[]
    },
    mounted:function(){
        this.searchObject = this.getQueryStringArgs();
        this.loginUid=this.searchObject&&this.searchObject.uid;
        //this.myWalletLog();
        this.myIncome();
    },
    methods:{
        //后退
        getBack:function(){
            // history.go(-1);
            location.href="/happyi/myWallet"
        },
        bgimg:function(url){
            url = url?url:"";
            return {
                "background-image":'url("'+url+'"),url("")'
            }
        },
        /*获取查询字符对象*/
        getQueryStringArgs: function () {
            //取得查询字符串并去掉开头的问号
            var qs = (location.search.length > 0 ? location.search.substring(1) : ""),
                args = {},
                items = qs.length ? qs.split("&") : [],
                item = null,
                name = null,
                value = null,
                len = items.length;
            for (var i = 0; i < len; i++) {
                item = items[i].split("=");
                name = item[0];
                value = item[1];
                if (name.length) {
                    args[name] = value;
                }
            }
            return args;
        },
        //我的钱包-明细
        myWalletLog:function(){
            var that=this;
            var data={
                loginUid:that.loginUid,
                pageNumber:that.pageNumber
            };
            this.ajax({url:"/happyi/myWalletLog",data:data,dataType:"json",method:"post"},function(b){
                if(b.json.code==0&&b.json.data){
                    that.walletLog=b.json.data;
                    that.walletLog1=that.walletLog.list;
                    if(that.walletLog.pageNumber>1){
                        if(that.walletLog.list.length>0) {
                            that.walletLog2 = that.walletLog2.concat(b.json.data.list);
                        }
                    }else{
                        that.walletLog2= that.walletLog1;
                    }
                    vm.loadFlag=false;
                }else{
                    that.walletLog={};
                    that.walletLog1=[];
                    that.walletLog2=[];
                    vm.$refs.prompt.toast("获取明细列表失败！")
                }
            });
        },
        //资产报表
        myIncome:function(){
            var that=this;
            var data={
                loginUid:that.loginUid,
                day:that.day
            };
            this.ajax({url:"/happyi/myIncome",data:data,dataType:"json",method:"post"},function(b){
                if(b.json.code==0&&b.json.data){
                    that.income=b.json.data;
                }else{
                    vm.$refs.prompt.toast("操作失败！");
                }
            });
        },
        getTab:function(day){
            this.day=day;
            this.data=[];
            this.list=[];
            this.myIncome();
        },
        setEcharts:function(){
            this.$nextTick(function(){
                var that=this;
                var myChart = echarts.init(document.getElementById("main"));
                var option = {
                    tooltip: {
                        trigger: 'axis'
                        // position: ['50%', '50%']

                    }, // position: function (pt) {
                    //     return [pt[0], '10%'];
                    // }
                    toolbox: {
                        feature: {
                            dataZoom: {
                                yAxisIndex: 'none'
                            },
                            restore: {},
                            saveAsImage: {}
                        }
                    },
                    xAxis: {
                        type: 'category',
                        boundaryGap: false,
                        data:that.list
                    },

                    yAxis: {
                        type: 'value',
                        boundaryGap: [0, '100%']
                    },
                    series: [
                        {
                            name:"收益",
                            type:'line',
                            smooth:true,
                            symbol: 'none',
                            sampling: 'average',
                            itemStyle: {
                                normal: {
                                    color: 'rgba(255,255,255,0.3)'
                                }
                            },
                            areaStyle: {
                                normal: {
                                    color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                                        offset: 0,
                                        color: 'rgba(0,149,255,0.3)'
                                    }, {
                                        offset: 1,
                                        color: 'rgba(255,255,255,0.3)'
                                    }])
                                }
                            },
                            data:that.data
                        }
                    ]
                };
                // 使用刚指定的配置项和数据显示图表。
                myChart.setOption(option);
            });
        },
        getNext:function(num){
            if(num==1){
                location.href="/happyi/incomeDetails?uid="+this.loginUid;
            }else if(num==2){
                location.href="/happyi/transaction?type=1&uid="+this.loginUid;
            }else if(num==3){
                location.href="/happyi/transaction?type=2&uid="+this.loginUid;
            }
        }
    },
    watch:{
        income:function(){
            this.$nextTick(function(){
                var that=this;
                console.log(that.income.days.length)
                for (var i = 0; i < that.income.days.length; i++) {
                    // if(i==0||i==that.income.days.length-1){
                    //     that.list.push(that.income.days[i].dates);
                    // }else{
                    //     that.list.push("");
                    // }
                    that.list.push(that.income.days[i].dates);
                    that.data.push(that.income.days[i].integral);
                }
                console.log(that.list)
                that.setEcharts();
            });
        }
    }
});
/*var width;
var height;
var myChart;
function browserRedirect() {
    var sUserAgent = navigator.userAgent.toLowerCase();
    var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
    var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
    var bIsMidp = sUserAgent.match(/midp/i) == "midp";
    var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
    var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
    var bIsAndroid = sUserAgent.match(/android/i) == "android";
    var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
    var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
    if (bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) {
        height = document.body.clientHeight/4
        width = document.body.clientWidth
        // alert(height)
        $("#main").css("width",width-30);
        $("#main").css("height",height);
        vm.setEcharts();
        $(window).resize(function() {
            width = document.body.clientWidth
            height = document.body.clientHeight/4
            $("#main").css("width",width-30);
            $("#main").css("height",height);
        });

    } else {
        alert("pc");
        //自适应设置
        width = $(window).width();
        height = $(window).height();
        // alert(height)
        $("#main").css("width",width-35);
        $("#main").css("height",height-360);
        vm.setEcharts();
        $(window).resize(function() {
            width = $(window).width();
            height = $(window).height();
            $("#main").css("width",width-35);
            $("#main").css("height",height-360);
        });
    }
}

window.onload=function(){
    browserRedirect()
};*/
/*
//文档高度
function getDocumentTop() {
    var scrollTop = 0, bodyScrollTop = 0, documentScrollTop = 0;
    if (document.body) {
        bodyScrollTop = document.body.scrollTop;
    }
    if (document.documentElement) {
        documentScrollTop = document.documentElement.scrollTop;
    }
    scrollTop = (bodyScrollTop - documentScrollTop > 0) ? bodyScrollTop : documentScrollTop;
    return scrollTop;
}
//可视窗口高度
function getWindowHeight() {
    var windowHeight = 0;
    if (document.compatMode == "CSS1Compat") {
        windowHeight = document.documentElement.clientHeight;
    } else {
        windowHeight = document.body.clientHeight;
    }
    return windowHeight;
}
//滚动条滚动高度
function getScrollHeight() {
    var scrollHeight = 0, bodyScrollHeight = 0, documentScrollHeight = 0;
    if (document.body) {
        bodyScrollHeight = document.body.scrollHeight;
    }
    if (document.documentElement) {
        documentScrollHeight = document.documentElement.scrollHeight;
    }
    scrollHeight = (bodyScrollHeight - documentScrollHeight > 0) ? bodyScrollHeight : documentScrollHeight;
    return scrollHeight;

}
window.onscroll=function(){
    var loadFlag = vm.walletLog.lastPage;
    //监听事件内容
    if(getScrollHeight()==getWindowHeight() + getDocumentTop()){
        //当滚动条到底时,这里是触发内容
        if(!loadFlag){
            vm.loadFlag=true;
            vm.pageNumber++;
            vm.myWalletLog();
        }else{
            // console.log("11111");
            vm.$refs.prompt.toast("没有更多了！")
        }
    }
};*/
